package com.zly.bscloud.controller;


import com.zly.bscloud.dto.UserDTO;
import com.zly.bscloud.entity.User;
import com.zly.bscloud.service.UserService;
import com.zly.bscloud.utils.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@RestController
@RequestMapping("/user")
@Api(tags = "用户接口")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/hello")
    public String hello(){
        System.out.println("aaa");
        return "hell000999";
    }

    @GetMapping("/hello1")
    public String hello1(){
        System.out.println("hello1");
        return "hell000888";
    }

    @ApiOperation(value = "根据用户名和密码进行用户登录(注册)")
    @ApiImplicitParam(name = "user" , value = "用户实体类 , 其中数据包含用户名和密码" , required = true , dataType = "User")
    @PostMapping("/login")
    public Result userLogin(@RequestBody User user){
        System.out.println("login");
        UserDTO userDTO = userService.userLogin(user);
        return Result.createSuccess(userDTO);
    }

    @ApiOperation(value = "重设用户密码")
    @ApiImplicitParam(name = "map" , value = "其中数据包含手机号和新密码和旧密码" , required = true , dataType = "Map")
    @PutMapping("/reset")
    public Result userReset(@RequestBody Map<String,String> map){
        userService.userReset(map);
        return Result.createSuccess();
    }

    @ApiOperation(value = "重设昵称")
    @ApiImplicitParam(name = "map" , value = "其中数据包含用户id和新昵称" , required = true , dataType = "Map")
    @PutMapping("/reset-nickname")
    public Result resetNickname(@RequestBody Map<String,String> map){
        UserDTO userDTO = userService.resetNickname(map);
        return Result.createSuccess(userDTO);
    }

    @ApiOperation(value = "重设手机号码")
    @ApiImplicitParam(name = "map" , value = "其中数据包含用户id和手机号" , required = true , dataType = "Map")
    @PutMapping("/reset-telephone")
    public Result resetTelephone(@RequestBody Map<String,String> map){
        System.out.println(3333);
        UserDTO userDTO = userService.resetTelephone(map);
        return Result.createSuccess(userDTO);
    }

    @ApiOperation(value = "重设地址")
    @ApiImplicitParam(name = "map" , value = "其中数据包含用户id和地址" , required = true , dataType = "Map")
    @PutMapping("/reset-location")
    public Result resetLocation(@RequestBody Map<String,String> map){
        System.out.println(3333);
        UserDTO userDTO = userService.resetLocation(map);
        return Result.createSuccess(userDTO);
    }

    @ApiOperation(value = "重设性别")
    @ApiImplicitParam(name = "map" , value = "其中数据包含用户id和性别" , required = true , dataType = "Map")
    @PutMapping("/reset-sex")
    public Result resetSex(@RequestBody Map<String,String> map){
        System.out.println(3333);
        UserDTO userDTO = userService.resetSex(map);
        return Result.createSuccess(userDTO);
    }

    @GetMapping("/find-AllUsers")
    public Result findAllUsers(){
        List<UserDTO> userDTOList = userService.findAllUsers();
        System.out.println(userDTOList);
        return Result.createSuccess(userDTOList);
    }
}
